﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">
      
      <div style="margin: 20px;">

        <p>
          Enter a search term below, to retrieve all list items site wide that contain the search term in their <strong>Title</strong>, <strong>Comments</strong> or <strong>Content</strong>.
          The search will operate over the latest lucene index, so ensure that this index is refreshed on a regular basis. Results can be sorted by any of the headers.
        </p>
        
        <p>
          <form runat="server">
            <table border="0">
              <tr>
                <td style="font-weight: bold;font-size: 0.7em">Search Term:&#160;</td>
                <td>
                  <input type="text" name="SearchText" id="SearchText" value="{Control/@SearchText}" />&#160;<span id="errorText" style="color:red;font-size: 0.7em"></span>
                </td>
              </tr>
              <tr>
                <td style="font-weight: bold;font-size: 0.7em">Content Type:&#160;</td>
                <td>
                  <select name="ContentTypeFilter">
                    <option value="">All Content Types</option>
                    <xsl:for-each select="Control/ContentType">
                      <option value="{.}">
                        <xsl:if test="/Control/@SelectedContentType = .">
                          <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="."/>                        
                      </option>
                    </xsl:for-each>
                  </select>              
                </td>
              </tr>
            </table>
            <input type="submit" value="Search" onclick="return testInput()" />
          </form>
        </p>

        <xsl:choose>
          <xsl:when test="Control/Result">
            <p>
              Note: The item title's link to their <strong>properties</strong> page.
            </p>
            
            <table id="resultsTable" class="tablesorter">
              <thead>
                <tr>
                  <th>Title</th>
                  <th>Content Type</th>
                  <th>Created</th>
                  <th>Modified</th>
                  <th>Web</th>
                  <th>List</th>
                </tr>
              </thead>
              <tbody>
                <xsl:for-each select="Control/Result">
                  <tr>
                    <td><a href="{@Path}"><xsl:value-of select="@Title" /></a></td>
                    <td><xsl:value-of select="@ContentType" /></td>
                    <td><xsl:value-of select="@Created" /></td>
                    <td><xsl:value-of select="@Modified" /></td>
                    <td><xsl:value-of select="@Web" /></td>
                    <td><xsl:value-of select="@List" /></td>
                  </tr>
                </xsl:for-each>
              </tbody>
            </table>
          </xsl:when>
          <xsl:when test="Control/@SearchAttempted">
            <h3>0 Results Found</h3>
          </xsl:when>
        </xsl:choose>
      </div>

      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
      <script src="/_layouts/spsearch/jquery.tablesorter.min.js"></script>
      <script>
        <![CDATA[
          $().ready(function()
          {
            $("#resultsTable").tablesorter(
            {
              textExtraction: 'complex',
              dateFormat: 'uk',
              widthFixed: true
            });
          });
          
          function testInput()
          {
            if($('#SearchText').val() != '')
              return true;
              
            $('#errorText').text('Please enter some text to search for.')
            return false;
          }
        ]]>
      </script>
      
    </xsl:template>
</xsl:stylesheet>
